package us.lithub.ui.dialog;

import us.lithub.R;
import us.lithub.Util;
import us.lithub.data.WebConnector;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

/**
 * Activity to add a book when there is no scanner possible
 */
public class AddBookManually extends Activity {

	/**
	 * Invoked at the start of the activity 
	 */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.dialog_add_book_manually);
		setResult(RESULT_CANCELED);
	}
	
	/**
	 * Invoked when the user presses the okay button
	 *
	 * @param view the view
	 */
	public void okay(View view) {
		EditText edtIsbn = (EditText) findViewById(R.id.edtIsbn);
		String isbn = edtIsbn.getText().toString();
		WebConnector wb = WebConnector.getInstance();
		
		String username = Util.getUsername(this);
		String password = Util.getPassword(this);
		wb.addBook(username, password, isbn);
		finish();
	}
}
